package leetcode;

import java.util.HashMap;
import java.util.Map;

public class _167_TwoSum2 {
    class Solution {

        public int[] twoSum(int[] nums, int target){
            int i = 0, j = nums.length-1;
            int temp = 0;
            while (i < j){
                temp = nums[i] + nums[j];
                if (temp == target){
                    return new int[]{i+1,j+1};
                }else if (temp > target){
                    j--;
                }else i++;
            }
            throw new IllegalArgumentException("no result!");
        }
    }

    public _167_TwoSum2.Solution getSolution(){
        return new _167_TwoSum2.Solution();
    }

    public static void main(String[] args){
        _167_TwoSum2 c = new _167_TwoSum2();
        _167_TwoSum2.Solution s = c.getSolution();
        int[] nums = {0, 1, 2,3,4};
        int target = 4;
        int[] res = s.twoSum(nums, target);
        System.out.println("res0:"+res[0]);
        System.out.println("res1:"+res[1]);
    }
}
